<?php
/**
 * cache.f.class.php 缓存工厂类
 *
 * 统一规范缓存共享方法 
 *
 * @author          hyperblue
 * @version         0.1
 * @copyright       (C) 2011- *
 * @license	        http://www.bingceng.com
 * @lastmodify	    2011-11-14 10:09
 */
 
defined('BC_INC_PATH') or exit("Access Denied!");

class Fcache {

	static private $_error = NULL;
	
	static private $_config = array();
	
	static private $_adapter = NULL;
	
	/**
	 * 构造函数
	 * @param $config array
	 */
	public function __construct($config) {
		//self::getConfig($config);
		//self::factory();
		//self::error();
	}
	
	/**
	 * 获取缓存配置
	 *
	 * @param $config array
	 * @return void
	 */
	static public function getConfig($config) {
		self::$_config = $config;
	}
	
	/**
	 * 缓存工厂
	 *
	 * 根据缓存存储类型实例化对应缓存对象，赋值给类的静态成员变量
	 */
	static function factory() {
		$cacheType = self::$_config['type'];
		if (!self::$_adapter) {
			switch ($cacheType) {
				case 'memcache':
					self::$_adapter = new cache_memcache(self::$_config);
					break;
				case 'apc':
					self::$_adapter = new cache_apc(self::$_config);
					break;
				case 'xml':
					self::$_adapter = new cache_xml(self::$_config);
					break;
				case 'ttserver':
					self::$_adapter = new cache_ttserver(self::$_config);
					break;
				case 'mongo':
					self::$_adapter = new cache_mongo(self::$_config);
					break;
				default:
					self::$_adapter = new cache_file(self::$_config);
					break;
			}
		}
		
		return self::$_adapter;
	}
	
	/**
	 * 错误提示
	 */
	static public function error() {
		if (self::$_error) {
			die(self::$_error);
			exit();
		}
	}
}

?>
